package code;

/**
 * Contains the checking account information
 *
 *
 */
public class CheckingAccount extends BankAccounts
{
	private boolean fDebitAllowed;
	private double fDebitAmount;
	private static double debitRate = 4.7;
	/*
	 * I would leave in fCreditCard, fSavingsAccount, fDebitCard however since there
	 * wasn't any behavior associated in the original code I decided to remove those fields
	 * but in reality I would leave them in and attach behavior them. 
	 */
	
	/**
	 * Creates a new Checking Account with no debit allowed
	 */
	public CheckingAccount()
	{
		fAccountNumber = fNextAccountNumber;
		fNextAccountNumber++;
		fDebitAllowed = false;
		fDebitAmount = 0;
	}
	
	/**
	 * Creates a new Checking account with debit allowed. 
	 * @param debit amount debit. 
	 */
	public CheckingAccount(float debit)
	{
		fAccountNumber = fNextAccountNumber;
		fNextAccountNumber++;
		fDebitAllowed = true;
		fDebitAmount = debit;
	}
	
	/**
	 * Determine the cost associated with the bank 
	 */
	public void determineCosts()
	{
		fBalance = fBalance - costs;
		if(fBalance < 0)
		{
			fBalance = fBalance - (fBalance * debitRate / 100);
		}
	}
	
	public boolean withdrawal(double amount)
	{
		if(((fBalance - amount) < 0) && (!fDebitAllowed))
		{
			return false;
		}
		else if((fBalance - amount) < -fDebitAmount)
		{
			fBalance = fBalance - amount;
			return true;
		}
		else
		{
			return false;
		}
	}

	/**
	 * Gets the debit amount
	 * @return debit amount
	 */
	public double getDebitAmount()
	{
		return fDebitAmount;
	}
	
	@Override
	public boolean equals(Object o)
	{
		if(fAccountNumber == ((CheckingAccount)o).fAccountNumber)
			return true;
		else
			return false;
				
	}
}
